package com.sw.study.mybatis.practice.dynamicsql;

import com.sw.study.mybatis.practice.pojo.Order;
import com.sw.study.mybatis.practice.pojo.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by sw on 2020/3/30.
 */
public interface OrderMapper {

    public List<Order> findOrders();

    /**
     * 根据用户信息查询订单
     * @param uid
     * @return
     */
    @Select("select * from tb_orders where uid=#{uid}")
    public List<Order> selectOrderByUId(Long uid);


    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "totalPrice",column = "total_price"),
            @Result(property = "user",column ="uid" ,javaType= User.class,one=@One(select = "com.sw.study.mybatis.practice.annotation.UserAnnotationMapper.selectUserById"))
    })
    @Select("select * from tb_orders where id=#{id}")
    public Order selectOderAndUser(Long id);

}
